var Tile = function(rawObject,shouldCollide){
    Drawable.call(this,rawObject,shouldCollide);
    this.personage = rawObject.personage;
    this.fertility = rawObject.fertility;
    this.maxFertility = rawObject.maxFertility;
    this.humidity = rawObject.humidity;
    this.isShape = true;
    this.color = "";
}

Tile.prototype = {
    load : function(engine, densityMap){
        if (this.showing || !this.shouldShow)
            return;

        this.spriteSheet = new engine.BaseSheet({x:this.x, y :this.y,z: 0},
            {alphaD:90,betaD:0,gammaD:0},
            {w:this.width,h:this.height});
        if(this.personage != null)
            this.color = "#007D29";
        else
            this.color = "#5D7E36";

        this.spriteSheet.color = this.color;
        this.showing = true;
    },

    delete : function(){
        if (this.showing){
            this.spriteSheet.destroy();
            this.showing = false;
        }
    },

    getInfos : function(){
        var infos = new Array();

        infos["Humidité"] = this.humidity + "%";
        infos["Fertilité"] = this.fertility + "%";
        infos["Fertilité max"] = this.maxFertility + "%";
        infos["Propriétaire"] = (this.personage == null) ? "Nobody" : this.personage;


        return infos;
    },


    consume : function(humidity, fertility){

        this.humidity -= humidity;
        this.fertility -= fertility;

        var success = true;

        if (this.humidity <= 0){
            this.humidity = 0;
            success = false;
        }
        if (this.fertility <= 0){
            this.fertility = 0;
            success = false;
        }
        this.save();

        return success;


    },

    save : function(){
        var save = this;
        save.coordinateX = this.x;
        save.coordinateY = this.y;
        save.coordinateZ = 0;

        World.instance.networkManager.saveTile(this);
    }



}